package com.is.common.utils;

import com.is.common.rx.BaseUrl;

import java.security.MessageDigest;
import java.util.HashMap;

/**
 * @author Administrator
 * @date 2017/4/7 0007
 */

public class Futils {
    public static HashMap<String, Object> geBaseUrlValue(Class cls) {
        HashMap<String, Object> hashMap = new HashMap<>();
        boolean exist = cls.isAnnotationPresent(BaseUrl.class);
        if (exist) {
            BaseUrl anno = (BaseUrl) cls.getAnnotation(BaseUrl.class);
            hashMap.put("host", anno.host());
            hashMap.put("port", anno.port());
        }
        return hashMap;
    }
    /**
     * getMD5
     *
     * @param source
     * @return String
     */
    public static String getMD5(String source) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(source.getBytes());
            byte messageDigest[] = digest.digest();
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < messageDigest.length; i++) {
                String hex = Integer.toHexString(0xFF & messageDigest[i]);
                if (hex.length() < 2) {
                    hex = "0" + hex;
                }
                stringBuilder.append(hex);
            }
            return stringBuilder.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
